<template>
  <view class="executive-introduction-container">
    <!-- 标题 -->
    <view class="header">
      <text class="title">添加高管</text>
      <text class="description">公司主要管理人员的介绍</text>
    </view>

    <!-- 高管形象 -->
    <view class="section info">
      <text class="section-title ">高管形象</text>
      <view class="upload-area" @click="uploadImage">
        <image v-if="executiveImage" :src="executiveImage" mode="aspectFill" class="image"></image>
      </view>
    </view>

    <!-- 高管姓名 -->
    <view class="section">
      <text class="section-title">高管姓名</text>
      <input
        v-model="executiveName"
        placeholder="请输入"
        class="input"
      />
    </view>

    <!-- 担职任务 -->
    <view class="section">
      <text class="section-title">担职任务</text>
      <input
        v-model="executivePosition"
        placeholder="请输入"
        class="input"
      />
    </view>

    <!-- 保存按钮 -->
    <view class="save-button-container">
      <button class="save-button" @click="saveExecutive">保存</button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      executiveImage: "/static/img/upload.svg", // 高管形象图片
      executiveName: "", // 高管姓名
      executivePosition: "", // 担职任务
    };
  },
  methods: {
    // 上传高管形象
    uploadImage() {
      uni.chooseImage({
        count: 1,
        sizeType: ["compressed"],
        sourceType: ["album", "camera"],
        success: (res) => {
          this.executiveImage = res.tempFilePaths[0];
        },
        fail: (err) => {
          uni.showToast({
            title: "上传失败，请重试",
            icon: "none",
          });
        },
      });
    },
    // 保存高管信息
    saveExecutive() {
      if (!this.executiveImage || !this.executiveName || !this.executivePosition) {
        uni.showToast({
          title: "请填写完整信息",
          icon: "none",
        });
        return;
      }

      const executiveData = {
        image: this.executiveImage,
        name: this.executiveName,
        position: this.executivePosition,
      };

      // 返回上一页并传递数据
      const eventChannel = this.getOpenerEventChannel();
      eventChannel.emit("updateExecutive", executiveData);

      uni.navigateBack();
    },
  },
};
</script>

<style scoped>
.executive-introduction-container {
  padding: 20px;
  background-color: #fff;
}

.header {
  margin-bottom: 20px;
}

.title {
  font-size: 18px;
  font-weight: bold;
  color: #151515;
  display: block;
  margin-bottom: 10px;
}

.description {
  font-size: 14px;
  color: #666;
}

.section {
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid #ebebeb;
}

.info{
	display: flex;
	justify-content: space-between;
	align-items: center;
}

.section-title {
  font-size: 16px;
  color: #151515;
  display: block;
  margin-bottom: 10px;
}

.upload-area {
  width: 50px;
height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  font-size: 16px;
}

.upload-area image {
  width: 100%;
  height: 100%;
}

.input {
  width: 100%;
  font-size: 14px;
}

.save-button-container {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background-color: #fff;
  padding: 10px 20px;
  box-shadow: 0 -2px 4px rgba(0, 0, 0, 0.1);
}

.save-button {
  width: 100%;
  height: 80rpx;
  line-height: 80rpx;
  background: linear-gradient(90deg, #9A9AFF 0%, #D6D6FE 100%);
  border-radius: 32px;
  font-size: 32rpx;
  color: #fff;
  text-align: center;
}
</style>